package com.glory.cqaospda.view.fragment

import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.RequiresApi
import androidx.databinding.DataBindingUtil
import com.glory.cqaospda.R
import com.glory.cqaospda.databinding.HomeFragmentBinding
import com.glory.cqaospda.view.SkipDialogActivity
import com.glory.cqaospda.viewmodel.HomeFragmentModel
import com.glory.mvvmnet.base.BaseFragment
import com.pda.platform.ui.ui_pdaplatform.entity.FreeUI_TabIndexGridEntity
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_StaticMembers

class MessageQueryFragment : BaseFragment<HomeFragmentModel>() {

    lateinit var binding: HomeFragmentBinding
    override fun layoutId(): Int {
        return R.layout.home_fragment
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding = DataBindingUtil.inflate(inflater, R.layout.home_fragment, container, false)
        return binding.root
    }

    @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
    override fun initView(savedInstanceState: Bundle?) {
        super.initView(savedInstanceState)
        binding.homeViewModel = viewModel
        activity?.let { viewModel.initAssets(it, "messagequery.txt") }
        viewModel.defUI.callObserve.observe(this) {
            when (it.type) {
                viewModel.START_ACTIVITY -> {
                    val entity = it.item as FreeUI_TabIndexGridEntity

                    val intent = Intent()
                    intent.putExtra(FreeApi_StaticMembers.SHOW_PLUGIN_KEY, entity.showPlugin)
                    intent.putExtra("Title", entity.text)
                    intent.putExtra("showPlugin", entity.showPlugin)
                    val clazz = Class.forName(entity.skipClass)
                    activity?.let { it1 -> intent.setClass(it1, clazz) }
                    startActivity(intent)

                }
            }
        }
    }

    override fun initData() {
        super.initData()

    }

}